package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.util.Log
import com.android.kotlincoroutinemvvmdemo.R

/*
* EnterFullScreenView
* */
class EnterFullScreenView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val degreeArr = floatArrayOf(0F, 120F, 240F)

    private val mStrokeWidth1 = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_CD4DF1)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeWidth = mStrokeWidth1
            strokeCap = Paint.Cap.ROUND
            style = Paint.Style.FILL_AND_STROKE
            color = context.resources.getColor(R.color.color_CD4DF1)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)

            drawLine(
                0F,
                -cy / 10,
                0F,
                cy / 10,
                mPaint1
            )

            drawLine(
                -cx / 10,
                0F,
                cx / 10,
                0F,
                mPaint1
            )

            val arcX = cx * 3 / 5
            val arcY = cy * 3 / 5
            mPaint0.strokeWidth = cx * 17 / 25
            for (degree in degreeArr) {
                save()
                rotate(degree)
                drawArc(
                    -arcX,
                    -arcY,
                    arcX,
                    arcY,
                    60F,
                    60F,
                    false,
                    mPaint0
                )
                restore()
            }
        }
    }
}